﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FinalProject.Data.Sort
{
    public class FieldSortOrder<T> : ISortCriteria<T> where T : class
    {
        public string Name { get; set; }
        public SortDirection Direction { get; set; }
        public FieldSortOrder()
        {
            this.Direction = SortDirection.Ascending;
        }
        public FieldSortOrder(string name, SortDirection direction)
            : base()
        {
            this.Name = name;
            this.Direction = direction;
        }
        public IOrderedQueryable<T> ApplyOrdering(IQueryable<T> query, Boolean useThenBy)
        {
            IOrderedQueryable<T> result = null;
            var desc = this.Direction == SortDirection.Descending;
            result = !useThenBy ? query.OrderBy(Name, desc) : query.ThenBy(Name, desc);
            return result;
        }
    }
}
